/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 08 - 28
 * Time: 21:23
 */
//牛客 判断是不是二叉搜索树
public class Solution4 {
    //法一 官方推荐方法
    int pre = Integer.MIN_VALUE;
    public boolean isValidBST (TreeNode root) {
        if(root == null) return true;//相当于中序遍历
        if(!isValidBST(root.left)) return false;
        if(root.val < pre) {
            return false;
        }else {
            pre = root.val;
        }
        return isValidBST(root.right);
    }
}
